//
//  SelectChapterView.m
//  ebook
//
//  Created by 吴超飞 on 16/6/21.
//  Copyright © 2016年 Moton. All rights reserved.
//

#import "SelectChapterView.h"
#import "UIImage+RTTint.h"

@interface SelectChapterView(){
    UILabel *chapterNameLabel;
    UILabel *percentLabel;
}

@end

@implementation SelectChapterView

-(instancetype)init{
    
    self = [super initWithFrame:CGRectMake(10, 0, MTScreenW-20, 50)];
    
    self.layer.cornerRadius = 5;
    if (self) {
        chapterNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, CGRectGetWidth(self.frame)-80, CGRectGetHeight(self.frame))];
        chapterNameLabel.font = [UIFont systemFontOfSize:14];
        chapterNameLabel.textAlignment = NSTextAlignmentLeft;
        [self addSubview:chapterNameLabel];
        
        percentLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(chapterNameLabel.frame), 0, 60, CGRectGetHeight(self.frame))];
        percentLabel.font = [UIFont systemFontOfSize:14];
        percentLabel.textAlignment = NSTextAlignmentRight;
        [self addSubview:percentLabel];
        
        UIImageView *arrowIv = [[UIImageView alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(self.frame)-2, 14, 10)];
        _arrowIv = arrowIv;
        arrowIv.centerX = self.centerX;
        arrowIv.contentMode = UIViewContentModeBottom;
        arrowIv.transform = CGAffineTransformMakeRotation(M_PI);
        [self addSubview:arrowIv];
    }
    
    [self setIsNight:_isNight];
    return self;
}

-(void)updateChapter:(NSString *)chapter percent:(float)percent{
    
    chapterNameLabel.text = chapter;
    percentLabel.text = [NSString stringWithFormat:@"%.1f%%", percent*100];
}

-(void)setIsNight:(BOOL)isNight{
    
    _isNight = isNight;
    self.backgroundColor = MTConfigColor(isNight?@"MTReaderToolBar_Bg_Color":@"MTReaderToolBar_DayBg_Color");
    _arrowIv.image = [[UIImage imageNamed:@"more_popver_arrow"] rt_tintedImageWithColor:MTConfigColor(isNight?@"MTReaderToolBar_Bg_Color":@"MTReaderToolBar_DayBg_Color")];
    
    UIColor *textColor = MTConfigColor(_isNight?@"MTReaderBar_NightNomarlText_Color":@"MTReaderBar_DayNomarlText_Color");
    chapterNameLabel.textColor = textColor;
    percentLabel.textColor = textColor;
}

@end
